package com.tyylab.kestrel.plugins.nacos.sharens.config;

import com.alibaba.cloud.nacos.ConditionalOnNacosDiscoveryEnabled;
import com.alibaba.cloud.nacos.NacosDiscoveryProperties;
import com.alibaba.cloud.nacos.NacosServiceManager;
import com.alibaba.cloud.nacos.discovery.NacosDiscoveryAutoConfiguration;
import com.alibaba.cloud.nacos.discovery.NacosServiceDiscovery;
import com.tyylab.kestrel.plugins.nacos.sharens.config.properties.NacosShareProperties;
import com.tyylab.kestrel.plugins.nacos.sharens.impl.KestrelNacosServiceDiscovery;
import org.springframework.boot.autoconfigure.AutoConfigureBefore;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.cloud.client.ConditionalOnDiscoveryEnabled;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;

@Configuration(proxyBeanMethods = false)
@ConditionalOnDiscoveryEnabled
@ConditionalOnNacosDiscoveryEnabled
@AutoConfigureBefore({NacosDiscoveryAutoConfiguration.class})
@ComponentScan(basePackages = {"com.tyylab.kestrel.plugins.nacos.sharens.config.properties"
})
public class KestrelNacosDiscoveryAutoConfiguration {


    @Bean
    @ConditionalOnMissingBean
    public NacosServiceDiscovery nacosServiceDiscovery(
            NacosDiscoveryProperties discoveryProperties, NacosShareProperties nacosShareProperties, NacosServiceManager nacosServiceManager
    ) {
        return new KestrelNacosServiceDiscovery(discoveryProperties, nacosShareProperties, nacosServiceManager);
    }
}
